package com.aaa.entity;


import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;
import java.util.List;

public class User implements UserDetails {

  private Integer uid;
  private String name;
  private String sex;
  private String phone;
  private String idcard;
  private String site;
  private String remarks;
  @DateTimeFormat(pattern = "yyyy-MM-dd")
  @JsonFormat(pattern = "yyyy-MM-dd")
  @TableField("entry")
  private String entry;
  @DateTimeFormat(pattern = "yyyy-MM-dd")
  @JsonFormat(pattern = "yyyy-MM-dd")
  @TableField("dimission")
  private String dimission;
  private String head;
  private String username;
  private String password;
  private String state;
  private Integer rid;
  @TableField(exist = false)
  private Collection<? extends GrantedAuthority> authorities;
  public User() {
  }

  public void setAuthorities(String... authorities) {
    List<GrantedAuthority> authorityList = AuthorityUtils.createAuthorityList(authorities);
    this.authorities = authorityList;
  }

  public User(Integer uid, String name, String sex, String phone, String idcard, String site, String remarks, String entry, String dimission, String head, String username, String password, String state, Integer rid, Collection<? extends GrantedAuthority> authorities) {
    this.uid = uid;
    this.name = name;
    this.sex = sex;
    this.phone = phone;
    this.idcard = idcard;
    this.site = site;
    this.remarks = remarks;
    this.entry = entry;
    this.dimission = dimission;
    this.head = head;
    this.username = username;
    this.password = password;
    this.state = state;
    this.rid = rid;
    this.authorities = authorities;
  }

  public long getUid() {
    return uid;
  }

  public void setUid(Integer uid) {
    this.uid = uid;
  }


  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }


  public String getSex() {
    return sex;
  }

  public void setSex(String sex) {
    this.sex = sex;
  }


  public String getPhone() {
    return phone;
  }

  public void setPhone(String phone) {
    this.phone = phone;
  }


  public String getIdcard() {
    return idcard;
  }

  public void setIdcard(String idcard) {
    this.idcard = idcard;
  }


  public String getSite() {
    return site;
  }

  public void setSite(String site) {
    this.site = site;
  }


  public String getRemarks() {
    return remarks;
  }

  public void setRemarks(String remarks) {
    this.remarks = remarks;
  }


  public String getEntry() {
    return entry;
  }

  public void setEntry(String entry) {
    this.entry = entry;
  }


  public String  getDimission() {
    return dimission;
  }

  public void setDimission(String dimission) {
    this.dimission = dimission;
  }


  public String getHead() {
    return head;
  }

  public void setHead(String head) {
    this.head = head;
  }

  @Override
  public String toString() {
    return "User{" +
            "uid=" + uid +
            ", name='" + name + '\'' +
            ", sex='" + sex + '\'' +
            ", phone='" + phone + '\'' +
            ", idcard='" + idcard + '\'' +
            ", site='" + site + '\'' +
            ", remarks='" + remarks + '\'' +
            ", entry=" + entry +
            ", dimission=" + dimission +
            ", head='" + head + '\'' +
            ", username='" + username + '\'' +
            ", password='" + password + '\'' +
            ", state='" + state + '\'' +
            ", rid=" + rid +
            '}';
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getState() {
    return state;
  }

  public void setState(String state) {
    this.state = state;
  }

  public Integer getRid() {
    return rid;
  }

  public void setRid(Integer rid) {
    this.rid = rid;
  }


  public User(Integer uid, String name, String sex, String phone, String idcard, String site, String remarks, String entry, String dimission, String head, String username, String password, String state, Integer rid) {
    this.uid = uid;
    this.name = name;
    this.sex = sex;
    this.phone = phone;
    this.idcard = idcard;
    this.site = site;
    this.remarks = remarks;
    this.entry = entry;
    this.dimission = dimission;
    this.head = head;
    this.username = username;
    this.password = password;
    this.state = state;
    this.rid = rid;
  }

  @Override
  public Collection<? extends GrantedAuthority> getAuthorities() {
    return this.authorities;
  }

  @Override
  public String getPassword() {
    return this.password;
  }

  @Override
  public String getUsername() {
    return this.name;
  }

  @Override
  public boolean isAccountNonExpired() {
    return true;
  }

  @Override
  public boolean isAccountNonLocked() {
    return true;
  }

  @Override
  public boolean isCredentialsNonExpired() {
    return true;
  }

  @Override
  public boolean isEnabled() {
    return true;
  }
}
